<template>
	<view class="content">
		<view class="title" v-if="count!=0">
			我的团队：{{count}}人
		</view>
		<view class="inner_list" v-for="(item,index) in tremList" :key="index">
			<image :src="imgUrl+item.avatar" mode=""></image>
			<view class="right">
				<view class="name">{{item.nickname}}</view>
			</view>
		</view>
		<view class="no_thing" v-if="noOrder">
			<image src="../../../static/icon/no_order.png"></image>
			<view class="no_thing_text">暂无内容</view>
		</view>
		<view class="over" v-if="flag">我也是有底线的</view>
		<is-login v-on:childClick='listenToClose' v-on:childClickAgain='listenToCloseAgain' v-if="isLogin==0"></is-login>
	</view>
</template>

<script>
	import isLogin from '../../../components/isLogin.vue'
	export default {
		data() {
			return {
				tremList: [],
				count: '',
				isLogin: 1,
				page: 1,
				limit: 15,
				imgUrl:'',
				flag:false,
				noOrder:false
			}
		},
		components: {
			isLogin,
		},
		onLoad() {
			let that = this
			this.imgUrl = that.$imgUrl
			if (!uni.getStorageSync('openid')) {
				this.isLogin = 0
			} else {
				this.getNumberTrem()
			}
		},
		onShow() {},
		onPullDownRefresh() {
			this.page = 1
			// this.tremList = []
			this.flag = false
			this.noOrder = false
			uni.showToast({
				icon: 'loading',
				title: '加载中',
			});
			setTimeout(() => {
				this.getNumberTrem(() => {
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
			}, 1000)
		},
		onReachBottom() {
			if (this.tremList.length < this.page * this.limit) {
				return this.flag = true
			}
			this.noOrder = false
			this.page++
			this.getNumberTrem()
		},
		methods: {
			getNumberTrem(callback) {
				let that = this
				var data = {
					openid: uni.getStorageSync('openid'),
					page: that.page,
					limit: that.limit
				}
				this.$myRequest.post(this.$api.distribution.getTeamUserPage, data).then(res => {
					if (res.code == '200') {
						callback && callback()
						that.count = res.data.count
						if (that.page == 1) {
							if (res.data.data.length == 0) {
								return this.noOrder = true
								this.flag = false
							}
							if(res.data.data.length < this.limit){
								 this.flag = true
							}
							this.tremList = res.data.data
						} else {
							this.tremList = [...this.tremList, ...res.data.data]
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			listenToClose(msg) {
				this.isLogin = msg
			},
			listenToCloseAgain() {
				this.getNumberTrem()
			},
		},
	}
</script>

<style scoped lang="scss">
	.content {
		width: 690rpx;
		margin: 0 auto;

		.title {
			width: 689rpx;
			height: 80rpx;
			background: #FFFFFF;
			box-shadow: 0px 2rpx 10rpx 0px rgba(90, 96, 105, 0.14);
			border-radius: 10rpx;
			line-height: 80rpx;
			text-indent: 20rpx;
			color: #333333;
			font-size: 26rpx;
			margin-top: 20rpx;
		}

		.inner_list {
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #E5E5E5;
			margin-top: 15rpx;
			image {
				width: 64rpx;
				height: 64rpx;
				padding: 20rpx 18rpx 20rpx 0;
				border-radius: 100%;
			}

			.right {
				margin-left: 15rpx;

				.name {
					color: #333333;
					font-size: 24rpx;
				}

				.time {
					font-size: 20rpx;
					color: #999999;
				}
			}
		}
	}
</style>
